package org.inasnet;

import org.inasnet.frame.DebugFrame;
import org.inasnet.frame.MainFrame;
import org.inasnet.frame.RegistryFrame;
import org.inasnet.user.ClientUser;

public class Root
{
	public static void init( String [] args ) 
	{
		try
		{
			mDebugShell = new DebugFrame();	
			
			//RegistryFrame rf = new RegistryFrame( "http://auth.inasnet.tu2.ru/comm.php?step=start_reg" );

			
			mDebugShell.log( "Prog starts: " + getProgramName() + " version " + getProgramVersion() );

			//mUser = new ClientUser( "0" );
			mUser = new ClientUser( ClientUser.detectUser() );
			
			mUser.startUp();
			
			mMainShell = new MainFrame( mUser );
			
			while( true )
			{
				boolean exitCode = false;
				
				mUser.doSession();
				
				Thread.currentThread().setPriority( Thread.MIN_PRIORITY );
				
				if( exitCode )
				{
					break;
				}
			}
		}
		/*catch( ExitProgramException e )
		{
			e.printStackTrace();
		}*/
		catch( Exception e )
		{
			e.printStackTrace();
		}
		
		mDebugShell.log( "Prog finished" );
	}
	

	public static void log( String message ) 
	{
		mDebugShell.log( message );
	}
	
	public static void loadLangPack( String pack )
	{
		mLanguagePack.loadAsConfigFormatFromFile( "config/lang/" + pack + ".txt" );
	}
		
	public static String lang( String key )
	{
		try
		{
			String value = mLanguagePack.get( key );
			
			return value;
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
		
		return "[No lang!]";
	}
	
	public static ClientUser getUser()
	{
		return mUser;
	}
	
	static String getProgramVersion()
	{
		return mProgramVersion;
	}
	
	static String getProgramName()
	{
		return mProgramName;
	}
	
	static StringMap mLanguagePack = new StringMap();
	
	static MainFrame mMainShell;
	static DebugFrame mDebugShell;
	
	static ClientUser mUser;
	
	static String mProgramName = "INASnet Chat";
	static String mProgramVersion = "0.0.0";
	
}
